﻿Imports UCBase

Public Class ComMonitor
    Implements UCBase.I_BinaryDataExchange

    Implements UCBase.I_LoadSave
    Private DataIO As UCBase.I_BinaryDataExchange
    Private m_BytesToRead As Integer
    Private m_BytesToWrite As Integer

    Private Sub DataOut_Connect() Handles DataOut.Connect
        Dim S As Socket = DataOut.Remote
        DataIO = S.Parent
    End Sub

    Public ReadOnly Property BytesToRead() As Integer Implements UCBase.I_BinaryDataExchange.BytesToRead
        Get
            m_BytesToRead = DataIO.BytesToRead
            Label6.Text = m_BytesToRead
            Return m_BytesToRead
        End Get
    End Property
    Public ReadOnly Property BytesToWrite() As Integer Implements UCBase.I_BinaryDataExchange.BytesToWrite
        Get
            Return m_BytesToWrite
        End Get
    End Property
    Public Sub ClearBuffers() Implements UCBase.I_BinaryDataExchange.ClearBuffers
        DataIO.ClearBuffers()
    End Sub

    Public Function Read() As Byte() Implements UCBase.I_BinaryDataExchange.Read
        Dim Data(DataIO.BytesToRead - 1) As Byte
        Data = DataIO.Read
        Dim S As String = "Read : Byte Array = {"
        For Each B As Byte In Data
            S = S & B.ToString & ","
        Next
        S = S.Substring(0, S.Length - 1)
        S = S & "}"
        ListBox1.Items.Add(S)
        m_BytesToRead = Data.Length
        Return Data
    End Function

    Public Sub Write(ByVal data() As Byte) Implements UCBase.I_BinaryDataExchange.Write
        Dim S As String = " Write : Byte Array = {"
        For Each B As Byte In data
            S = S & B.ToString & ","
        Next
        S = S.Substring(0, S.Length - 1)
        S = S & "}"
        ListBox1.Items.Add(S)
        DataIO.Write(data)
    End Sub

    Private Sub Button3D1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3D1.Click
        ListBox1.Items.Clear()
    End Sub

    Private Sub ComMonitor_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Me.Width = 400
        Me.Height = 240
    End Sub

    Public Function GetSettings() As String Implements UCBase.I_LoadSave.GetSettings
        Return ""
    End Function

    Public Sub SetSettings(ByVal Settings As String) Implements UCBase.I_LoadSave.SetSettings

    End Sub

    Private Sub ComMonitor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Timer1.Enabled = True

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If DataOut.Connected Then
            m_BytesToRead = DataIO.BytesToRead
            Label6.Text = m_BytesToRead
            m_BytesToWrite = DataIO.BytesToWrite
            Label7.Text = m_BytesToWrite
        End If

    End Sub

    Public Function Read1(ByVal Count As Integer) As Byte() Implements UCBase.I_BinaryDataExchange.Read
        Return Nothing
    End Function
End Class
